package com.nand.module.function.adapter;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.nand.module.function.R;
import com.nand.module.function.bean.EpairListBean;
import com.nand.module.function.bean.EqDatailBean;

import java.util.ArrayList;
import java.util.List;

/**
 * created by 86185
 * on 2019/12/24
 */
public class EpairListAdapter extends RecyclerView.Adapter<EpairListAdapter.ViewHolder> implements View.OnClickListener {
    private Context mContext;
    private int type;
    private List<EpairListBean.DataListBean> mList = new ArrayList<>();

    private EpairListAdapter.OnItemClickListener mOnItemClickListener = null;

    public EpairListAdapter(Context mContext, int type) {
        this.mContext = mContext;
        this.type = type;
    }

    public void setData(List<EpairListBean.DataListBean> data) {
        this.mList = data;
        notifyDataSetChanged();
    }


    @Override
    public EpairListAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View layout = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_epair_list, viewGroup, false);
        layout.setOnClickListener(this);
        return new EpairListAdapter.ViewHolder(layout);
    }

    @Override
    public void onBindViewHolder(EpairListAdapter.ViewHolder viewHolder, int position) {
        viewHolder.itemView.setTag(position);
        EpairListBean.DataListBean bean = mList.get(position);

        viewHolder.mTextview1.setText(Html.fromHtml("异常单号:&#12288;<font color='#696969'>"+bean.getProdAnoID()+"</font>"));
        int prodAnoTGrand = bean.getProdAnoTGrand();
        viewHolder.mTextview3.setText(Html.fromHtml("工&#12288;&#12288;序:&#12288;<font color='#696969'>"+bean.getProcessContent()+"</font>"));
        viewHolder.mTextview4.setText(Html.fromHtml("类&#12288;&#12288;别:&#12288;<font color='#696969'>"+bean.getProdAnoType()+"</font>"));
        viewHolder.mTextview5.setText(Html.fromHtml("创建时间:&#12288;<font color='#696969'>"+bean.getCreatedTime()+"</font>"));


        int state = bean.getState();
        switch (state){
            case 0:
                viewHolder.mTextview6.setText("待处理");
                viewHolder.mTextview6.setBackgroundResource(R.drawable.layout_color3);
              //  viewHolder.ivEpairSign.setVisibility(View.VISIBLE);

                break;
            case 1:
                viewHolder.mTextview6.setText("待确认");
                //viewHolder.ivEpairSign.setVisibility(View.VISIBLE);
                viewHolder.mTextview6.setBackgroundResource(R.drawable.layout_color2);
                break;
            case 2:
                viewHolder.mTextview6.setBackgroundResource(R.drawable.layout_color4);
                viewHolder.mTextview6.setText("关闭");
               // viewHolder.ivEpairSign.setVisibility(View.INVISIBLE);
                break;
            case 3:
                viewHolder.mTextview6.setText("待提交");
               // viewHolder.ivEpairSign.setVisibility(View.VISIBLE);
                viewHolder.mTextview6.setBackgroundResource(R.drawable.layout_color1);
                break;
            case 4:
                viewHolder.mTextview6.setBackgroundResource(R.drawable.layout_color4);
                viewHolder.mTextview6.setText("中止");
                //viewHolder.ivEpairSign.setVisibility(View.INVISIBLE);
                break;
            case 5:
                viewHolder.mTextview6.setBackgroundResource(R.drawable.layout_color4);
                viewHolder.mTextview6.setText("驳回处理");
              //  viewHolder.ivEpairSign.setVisibility(View.VISIBLE);
                break;
        }

        if (0 == prodAnoTGrand){
            viewHolder.mTextview2.setText(Html.fromHtml("等&#12288;&#12288;级:&#12288;<font color='#38A677'>轻微</font>"));
           // viewHolder.ivEpairSign.setImageResource(R.mipmap.epair_sign_green);
            //viewHolder.ivEpairSign.setImageResource(R.mipmap.grade_slight);
        }else  if (1 == prodAnoTGrand){
            viewHolder.mTextview2.setText(Html.fromHtml("等&#12288;&#12288;级:&#12288;<font color='#38A677'>一般</font>"));
           // viewHolder.ivEpairSign.setImageResource(R.mipmap.epair_sign_green);
           // viewHolder.ivEpairSign.setImageResource(R.mipmap.grade_general);
        }else {
            viewHolder.mTextview2.setText(Html.fromHtml("等&#12288;&#12288;级:&#12288;<font color='#FF3B5E'>严重</font>"));
            //viewHolder.ivEpairSign.setImageResource(R.mipmap.epair_sign_red);
           // viewHolder.ivEpairSign.setImageResource(R.mipmap.grade_serious);
        }

    }

    @Override
    public int getItemCount() {
        if (mList != null)
            return mList.size();
        return 0;
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        TextView mTextview1, mTextview2, mTextview3, mTextview4, mTextview5,mTextview6;
        ImageView ivEpairSign;

        public ViewHolder(View itemView) {
            super(itemView);
            mTextview1 = itemView.findViewById(R.id.textview1);
            mTextview2 = itemView.findViewById(R.id.textview2);
            mTextview3 = itemView.findViewById(R.id.textview3);
            mTextview4 = itemView.findViewById(R.id.textview4);
            mTextview5 = itemView.findViewById(R.id.textview5);
            mTextview6 = itemView.findViewById(R.id.textview6);
            ivEpairSign = itemView.findViewById(R.id.iv_epair_sign);


        }

    }
    //两次点击按钮之间的间隔，目前为1000ms
    private static final int MIN_CLICK_DELAY_TIME = 1000;
    private long lastClickTime;
    public static interface OnItemClickListener {

        void onItemClick(View view, int position);

    }

    @Override
    public void onClick(View v) {
        if (mOnItemClickListener != null) {
            long curClickTime = System.currentTimeMillis();
            if ((curClickTime - lastClickTime) >= MIN_CLICK_DELAY_TIME) {
                lastClickTime = curClickTime;
                //注意这里使用getTag方法获取position
                mOnItemClickListener.onItemClick(v, (int) v.getTag());
            }
        }
    }

    public void setOnItemClickListener(EpairListAdapter.OnItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }
}

